﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace CXmlDocument
{
   public class CXmlDocument
    {
       private XmlDocument _xmldoc;
       //根节点
       private XmlElement _rootNode;

       /// <summary>
       /// 从文件直接读取
       /// </summary>
       /// <param name="fileName"></param>
       public CXmlDocument(string fileName)
       {
           _xmldoc = new XmlDocument();
           _xmldoc.Load(fileName);
          _rootNode=_xmldoc.DocumentElement;
       }

       /// <summary>
       /// 获取所有节点
       /// </summary>
       /// <param name="xPath"></param>
       /// <returns></returns>
       public XmlNodeList SelectNodes(string xPath)
       {
          return _rootNode.SelectNodes(xPath);
       }

       /// <summary>
       /// 获取配置信息List
       /// </summary>
       /// <param name="listNodes"></param>
       /// <returns></returns>
       public List<string> GetNodesValueList(XmlNodeList listNodes)
       {
           List<string> lstText=new List<string>();
           foreach (XmlNode node in listNodes)
               lstText.Add(node.InnerText);
           return lstText;

       }
       /// <summary>
       /// 获取配置信息List
       /// </summary>
       /// <param name="xPath"></param>
       /// <returns></returns>
       public List<string> GetNodesValueList(string xPath) 
       { 
         return GetNodesValueList(SelectNodes(xPath));
       }
    }
}
